<%--
  Created by IntelliJ IDEA.
  User: User
  Date: 2020/6/1
  Time: 21:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>购票</title>
</head>
<jsp:useBean id="db" class='hello.DB'></jsp:useBean>
<body style="background:url(page/1.jpg)">
hello：<%out.print(session.getAttribute("user"));%>
<br><h1 align="center">购票页面</h1>
<%@ page import="java.sql.*" %>
<%	String begin=request.getParameter("begin");//获取出发地和终点
    session.setAttribute("begin",begin);
    String end=request.getParameter("end");
    session.setAttribute("end",end);

    String day="day0";
    if(request.getParameter("gender").equals("明天"))day="day1";
    else if(request.getParameter("gender").equals("后天"))day="day2";
    session.setAttribute("day",day);
    db.init();
    //查询车票
    String sql=
            "select s1.trainnum,s1.staname staname1,s2.staname staname2,s1.begintime,s2.arrivetime,"+
                    "datediff(mi,s1.begintime,s2.arrivetime) usetime,"+day+"_1 s1,"+day+"_2 s2,"+day+"_v sv "+
                    "from station s1 ,station s2,seat s "+
                    "where s1.staname='"+begin+"' and s2.staname='"+end+"' "+
                    "and s1.trainnum=s2.trainnum and s1.trainnum=s.trainnum "+
                    "and s1.stanum<s2.stanum "+
                    "and s2.stanum=s.stanum";
    ResultSet rs=db.executeQuery(sql);


    System.out.print(sql);
    if(rs.next()){
%><h3>您选择的日期是:<%out.print(request.getParameter("gender")); %></h3>
<table border="1" >
    <tr>
        <td>车次</td>
        <td>始-终</td>
        <td>出发时间</td>
        <td>到达时间</td>
        <td>历时(分钟)</td>
        <td>二等座余票</td>
        <td>一等座余票</td>
        <td>无座余票</td>
        <td>操作</td>
    </tr>
    <tr>
        <td><%out.print(rs.getString("trainnum")); %></td>
        <td><%out.print(rs.getString("staname1")+"-"+rs.getString("staname2")); %></td>
        <td><%out.print(rs.getString("begintime").substring(0,5)); %></td>
        <td><%out.print(rs.getString("arrivetime").substring(0,5)); %></td>
        <td><%out.print(rs.getString("usetime")); %></td>
        <td><%out.print(rs.getString("s2")); %></td>
        <td><%out.print(rs.getString("s1")); %></td>
        <td><%out.print(rs.getString("sv")); %></td>

        <td><a  href="ticket_pur.jsp?trainnum=<%=rs.getString("trainnum")%>">购买</a></td>
    </tr>

    <% 		while(rs.next()){
    %>
    <tr>
        <td><%out.print(rs.getString("trainnum")); %></td>
        <td><%out.print(rs.getString("staname1")+"-"+rs.getString("staname2")); %></td>
        <td><%out.print(rs.getString("begintime").substring(0,5)); %></td>
        <td><%out.print(rs.getString("arrivetime").substring(0,5)); %></td>
        <td><%out.print(rs.getString("usetime")); %></td>
        <td><%out.print(rs.getString("s2")); %></td>
        <td><%out.print(rs.getString("s1")); %></td>
        <td><%out.print(rs.getString("sv")); %></td>

        <td><a  href="ticket_pur.jsp?trainnum=<%=rs.getString("trainnum")%> ">购买</a></td>
    </tr>
</table>
<%		}
}
else out.print("无票");
    db.close();
%>
</body>
</html>
